﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using TileEngine.items;
using TileEngine.items.tiles.material;
namespace TileEngine.tiles.material
{
    class Tree : DefaultTile
    {
        public Tree(int x,int y)
        {
            this.x = x;
            this.y = y;
        }
        public Tree()
        {
        }
        public override Texture2D getTexture()
        {
            return Textures.tree;
        }
        override public bool breakTile()
        {
            Global.currentWorld.tiles[x, y].tile = new Empty(x,y);
            if (Global.currentWorld.tiles[x, y + 1].tile.GetType() == typeof(Tree))
                Global.currentWorld.tiles[x, y + 1].tile.breakTile();
            if (Global.currentWorld.tiles[x, y - 1].tile.GetType() == typeof(Tree))
                Global.currentWorld.tiles[x, y - 1].tile.breakTile();
            Global.currentWorld.items.Add(new WoodItem(new Vector2(x*Global.tileSize.X, y*Global.tileSize.Y)));
            return true;
        }
        override public Color getLight()
        {
            return Color.Black;
        }
        override public int getWidht()
        {
            return 0;
        }
        override public int getHeight()
        {
            return 0;
        }
        override public int getHardness()
        {
            return 10;
        }
        override public double getLightAbsorption()
        {
            return 0.7;
        }
        public override bool isWallvisible()
        {
            return true;
        }
        public override bool isObstacle()
        {
            return false;
        }
        public override bool canDigBottom()
        {
            return false;
        }
        public override void draw(SpriteBatch spriteBatch, Point destinationPoint, Color tint)
        {
            int frame = GetHashCode() % 8; ;
            if (Global.currentWorld.tiles[x, y - 1].tile.GetType() == typeof(Empty))
            {
                spriteBatch.Draw(Textures.treeTop, new Vector2(destinationPoint.X, destinationPoint.Y),null,
                 tint,0,new Vector2(100-Global.tileSize.X,140),0.5f,SpriteEffects.None,0);
            
            }
            else
            spriteBatch.Draw(getTexture(), new Rectangle(destinationPoint.X, destinationPoint.Y, Global.tileSize.X, Global.tileSize.Y),
                new Rectangle((frame % 4) * 20, ((int)(frame / 4)) * 20, Global.tileSize.X, Global.tileSize.Y), tint);
            
        }
        public override void setCoord(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }
}
